package org.langqiao.util.uniqueno;

import java.security.SecureRandom;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

/**
 * 随机书生成工具
 * 
 * @author mingxin
 */
public class RandomNumUtils {

	/** 生成一个num位随机数 (yyyyMMddHHmmssSSS + n位随机数[rdm.nextInt(10)]) */
	public static String createDateForNum(int num) {
		Random rdm = new Random();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
		StringBuffer buf = new StringBuffer();
		// 加上日期
		buf.append(sdf.format(new Date()));
		for (int i = 0; i <= num; i++) {
			// 取n个随机数追加到StringBuffer
			buf.append(rdm.nextInt(10));
		}
		return buf.toString();
	}

	public static String createDateForNum()  {
		Random rdm = new Random(System.currentTimeMillis());
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
		StringBuffer buf = new StringBuffer();
		// 加上日期
		buf.append(sdf.format(new Date()));
		for (int i = 0; i <= 6; i++) {
			// 取n个随机数追加到StringBuffer
			buf.append(rdm.nextInt(10));
			
		}
		return buf.toString();
	}

	/* 生成一个18为的随机数 */
	public static String createDate18Num() {
		Random rdm = new Random(System.currentTimeMillis());
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		StringBuffer buf = new StringBuffer();
		buf.append(sdf.format(new Date()));
		for (int i = 0; i < 4; i++) {
			buf.append(rdm.nextInt(10));
		}
		return buf.toString();
	}

	/** 生成一个UUID */
	public static String createUUID() {
		return UUID.randomUUID().toString();
	}
	
	public static void main(String[] args) {
		for (int i = 0; i < 10000; i++) {
			new Thread(new Runnable() {
				@Override
				public void run() {
					Math.random();
					SecureRandom secureRandom = new SecureRandom();
					secureRandom.nextInt();
					Random random = new Random();
					System.out.println((int)(Math.random()*10000)+1);
				}
			}).start();
		}

	}
}
